@echo off
@REM  ---------------------------------------------------------------------------------
@REM  RegAssemblies.bat file
@REM
@REM  This batch file installs/uninstalls all the assemblies for Enterprise Library 
@REM  contribution application blocks.  By default it installs all the assemblies in the debug dirs.
@REM  
@REM  Optional arguments for this batch file:
@REM    1 - /u to uninstall. Otherwise it is installed.
@REM    2 - /log to log to console
@REM    
@REM  ----------------------------------------------------------------------------------

echo.
echo ==========================================================================
echo   RegAssemblies.bat                                                    
echo      Installs/uninstalls assemblies for Enterprise Library Contribution
echo ==========================================================================
echo.

set InstallUtilDir=%WINDIR%\Microsoft.NET\Framework\v3.5\
set binDir="."
set action=
set logToConsole=false
set pause=true
set buildType=Debug

if "%1"=="/?" goto HELP

if "%1"=="" goto RUN

@REM  ----------------------------------------------------
@REM  If the first parameter is /q, do not pause
@REM  at the end of execution.
@REM  ----------------------------------------------------
if /i "%1"=="/q" (
 set pause=false
 SHIFT
)

@REM  ----------------------------------------------------
@REM  If the first parameter is /u, uninstall.
@REM  ----------------------------------------------------
if /i "%1"=="/u" (
 set action=%1
 SHIFT
)

@REM  ----------------------------------------------------
@REM  If the first parameter is /log, log to console.
@REM  ----------------------------------------------------
if /i "%1"=="/log" (
 set logToConsole=true
 SHIFT
)



:RUN
@REM  ------------------------------------------------
@REM  Shorten the command prompt for making the output
@REM  easier to read.
@REM  ------------------------------------------------
set savedPrompt=%prompt%
set prompt=*$g

@REM -------------------------------------------------------
@REM Set the current directory
@REM -------------------------------------------------------
if not Exist "%binDir%" goto HELP
pushd %binDir%

@REM  ----------------------------------------
@REM  Register VS.NET environment variables
@REM  (required to call installutil)
@REM  ----------------------------------------
if not Exist "%installUtilDir%" goto HELPFW
@set PATH=%PATH%;%installUtilDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Common Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Common
@REM ------------------------------------------------------------------
cd ..\Blocks\Common\Src\Common\bin\%buildType%
if Exist EntLibContrib.Common.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Common.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Common\Tests\Common.Tests\bin\%buildType%
if Exist EntLibContrib.Common.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Common.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Data Access Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Data Access
@REM ------------------------------------------------------------------
cd ..\Blocks\Data\Src\DB2\bin\%buildType%
if Exist EntLibContrib.Data.DB2.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.DB2.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\DB2.Tests\bin\%buildType%
if Exist EntLibContrib.Data.DB2.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.DB2.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

cd ..\Blocks\Data\Src\MySql\bin\%buildType%
if Exist EntLibContrib.Data.MySql.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.MySql.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\MySql.Tests\bin\%buildType%
if Exist EntLibContrib.Data.MySql.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.MySql.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

cd ..\Blocks\Data\Src\OdpNet\bin\%buildType%
if Exist EntLibContrib.Data.OdpNet.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.OdpNet.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\OdpNet.Tests\bin\%buildType%
if Exist EntLibContrib.Data.OdpNet.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.OdpNet.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

cd ..\Blocks\Data\Src\PostgreSql\bin\%buildType%
if Exist EntLibContrib.Data.PostgreSql.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.PostgreSql.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\PostgreSql.Tests\bin\%buildType%
if Exist EntLibContrib.Data.PostgreSql.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.PostgreSql.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

cd ..\Blocks\Data\Src\SqlEx\bin\%buildType%
if Exist EntLibContrib.Data.SqlEx.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.SqlEx.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\SqlEx.Tests\bin\%buildType%
if Exist EntLibContrib.Data.SqlEx.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.SqlEx.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

cd ..\Blocks\Data\Src\SQLite\bin\%buildType%
if Exist EntLibContrib.Data.SQLite.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.SQLite.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Data\Tests\SQLite.Tests\bin\%buildType%
if Exist EntLibContrib.Data.SQLite.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Data.SQLite.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Exception Handling Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Exception Handling
@REM ------------------------------------------------------------------
cd ..\blocks\ExceptionHandling\Src\ExceptionHandling\bin\%buildType%
if Exist EntLibContrib.ExceptionHandling.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.ExceptionHandling.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\ExceptionHandling\Tests\ExceptionHandling.Tests\bin\%buildType%
if Exist EntLibContrib.ExceptionHandling.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.ExceptionHandling.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Logging Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Logging
@REM ------------------------------------------------------------------
cd ..\Blocks\Logging\Src\Logging\bin\%buildType%
if Exist EntLibContrib.Logging.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Logging.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Logging\Tests\Logging.Tests\bin\%buildType%
if Exist EntLibContrib.Logging.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Logging.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Policy Injection Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Policy Injection Call Handlers
@REM ------------------------------------------------------------------
cd ..\Blocks\PolicyInjection\Src\PolicyInjection.CallHandlers\bin\%buildType%
if Exist EntLibContrib.PolicyInjection.CallHandlers.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.PolicyInjection.CallHandlers.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\PolicyInjection\Tests\PolicyInjection.CallHandlers.Tests\bin\%buildType%
if Exist EntLibContrib.PolicyInjection.CallHandlers.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.PolicyInjection.CallHandlers.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Query Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Query
@REM ------------------------------------------------------------------
cd ..\Blocks\Query\Src\Query\bin\%buildType%
if Exist EntLibContrib.Query.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Query.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Query\Tests\Query.Tests\bin\%buildType%
if Exist EntLibContrib.Query.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Query.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Query\Tests\Configuration.Manageability.Tests\bin\%buildType%
if Exist EntLibContrib.Query.Configuration.Manageability.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Query.Configuration.Manageability.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@REM Query Database
@REM ------------------------------------------------------------------
cd ..\Blocks\Query\Src\Database\bin\%buildType%
if Exist EntLibContrib.Query.Database.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Query.Database.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Query\Tests\Database.Configuration.Manageability.Tests\bin\%buildType%
if Exist EntLibContrib.Query.Database.Configuration.Manageability.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Query.Database.Configuration.Manageability.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Resource Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Resource
@REM ------------------------------------------------------------------
cd ..\Blocks\Resource\Src\Resource\bin\%buildType%
if Exist EntLibContrib.Resource.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Resource.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Resource\Tests\Resource.Tests\bin\%buildType%
if Exist EntLibContrib.Resource.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Resource.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Resource\Tests\Configuration.Manageability.Tests\bin\%buildType%
if Exist EntLibContrib.Resource.Configuration.Manageability.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Resource.Configuration.Manageability.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@REM Resource Database
@REM ------------------------------------------------------------------
cd ..\Blocks\Resource\Src\Database\bin\%buildType%
if Exist EntLibContrib.Resource.Database.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Resource.Database.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Resource\Tests\Database.Configuration.Manageability.Tests\bin\%buildType%
if Exist EntLibContrib.Resource.Database.Configuration.Manageability.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Resource.Database.Configuration.Manageability.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Validation Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

@REM Validation
@REM ------------------------------------------------------------------
cd ..\Blocks\Validation\Src\Validation\bin\%buildType%
if Exist EntLibContrib.Validation.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Validation.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%
cd ..\Blocks\Validation\Tests\Validation.Tests\bin\%buildType%
if Exist EntLibContrib.Validation.Tests.dll installutil %action% /LogToConsole=%logToConsole% EntLibContrib.Validation.Tests.dll
@if errorlevel 1 goto :error
popd
pushd %binDir%

@ECHO.
@ECHO ----------------------------------------
@ECHO RegAssemblies.bat Completed
@ECHO ----------------------------------------
@ECHO.

@REM  ----------------------------------------
@REM  Restore the command prompt and exit
@REM  ----------------------------------------
@goto :exit

@REM  -------------------------------------------
@REM  Handle errors
@REM
@REM  Use the following after any call to exit
@REM  and return an error code when errors occur
@REM
@REM  if errorlevel 1 goto :error	
@REM  -------------------------------------------
:error
@ECHO An error occured in RegAssemblies.bat - %errorLevel%
if %pause%==true PAUSE
goto exit

:HELPFW
echo Error: Unable to locate the .NET Framework
echo.
echo InstallServices.bat assumes the .NET Framework has been installed in its default location 
echo ("%visualStudioDir%".) 
echo.
echo If you have installed the .NET Framework v2.0 to a different location, you will need 
echo to update this batch file to reflect that location.
echo.
goto exit

:HELP
echo Usage: RegAssemblies.bat [/q] [/u] [build folder]  
echo.
echo Examples:
echo.
echo	"RegAssemblies" - installs assemblies for Enterprise Library assemblies       
echo	"RegAssemblies /u" - uninstalls assemblies for Enterprise Library assemblies 
echo	"RegAssemblies /q" - installs assemblies, no pause when error occurs (quiet mode)     
echo	"RegAssemblies /log" - logs output to the console 
echo.

@REM  ----------------------------------------
@REM  The exit label
@REM  ----------------------------------------
:exit

popd
set pause=
set binDir=
set prompt=%savedPrompt%
set savedPrompt=
set action=

echo on